package jy.service.impl;

import java.util.HashMap;
import java.util.Map;

import jy.dao.FoodDaoI;
import jy.dao.FtypeDaoI;
import jy.dao.StoreDaoI;
import jy.model.Food;
import jy.model.User;
import jy.pageModel.PFood;
import jy.service.FoodServiceI;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FoodServiceImpl implements FoodServiceI {

	@Autowired
	private FoodDaoI foodDao;
	
	@Autowired
	private FtypeDaoI ftypeDao;
	
	@Autowired
	private StoreDaoI storeDao;
	
	public Boolean add(PFood food) throws Exception{
		Food f = new Food();
		BeanUtils.copyProperties(food, f);
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", food.getStoreId());
		System.out.println(food.getStoreId());
		f.setStore(storeDao.get("select t from Store t  where t.id = :id", params));
		Map<String, Object> params2 = new HashMap<String, Object>();
		params.put("id", food.getTypeId());
		System.out.println(food.getTypeId());
		f.setFtype(ftypeDao.get("select t from Ftype t  where t.id = :id", params));
		foodDao.save(f);
		
		return true;
		
	}

	


}
